import os, sys
import pygame
from pygame.locals import *

from Gui.Gui import *
from Gui.GuiWnd import *
from Gui.GuiBtn import *
from Gui.GuiTxt import *
from Gui.GuiCbx import *
from Gui.GuiImg import *

def buttonClickedOK(parent_, gui_):
	parent_.parent.alive = 0
	text = GuiTxt(15,25,"Clicked OK", "data/fonts/bitstream.ttf", 12, (255,255,255))
	gui_.add(text)

def buttonClickedCancel(parent_, gui_):
	parent_.parent.alive = 0
	text = GuiTxt(15,25,"Clicked Cancel", "data/fonts/bitstream.ttf", 12, (255,255,255))
	gui_.add(text)

def checkedBox(parent_, gui_):
	if parent_.checked:
		parent_.text = "Not Checked"	
		parent_.checked = 0
	else:
		parent_.text = "Checked"
		parent_.checked = 1
	
pygame.init();
screen = pygame.display.set_mode((640,480),SWSURFACE)
gui = Gui()
window = GuiWnd(20,20,250,180, "Window Test", "data/fonts/bitstream.ttf")
button = GuiBtn(35,75,50,20, "Ok", "data/fonts/bitstream.ttf", 12)
button2 = GuiBtn(100,75,50,20, "Cancel", "data/fonts/bitstream.ttf", 14)
text = GuiTxt(10,30,"Do you wish to continue?", "data/fonts/bitstream.ttf", 20, (255,25,25))
check = GuiCbx(10,50,"Not Checked", "data/fonts/bitstream.ttf", 12)
image = GuiImg(12,95,"data/images/pygame.png")
button.onClick.append(buttonClickedOK)
button2.onClick.append(buttonClickedCancel)
check.onClick.append(checkedBox)
window.add(button)
window.add(button2)
window.add(text)
window.add(check)
window.add(image)
gui.add(window)

while gui.ready:
	pygame.draw.rect(screen, (0,0,0), (0, 0, 300, 300))
	gui.draw()
	gui.update()
	mpos = pygame.mouse.get_pos()
	hover = gui.getClick(mpos[0], mpos[1])
	for e in pygame.event.get():
			if e.type is QUIT: gui.ready = 0
			if e.type is KEYDOWN and e.key == K_ESCAPE: gui.ready = 0
			if e.type is MOUSEBUTTONUP: 
				clicked = gui.getClick(mpos[0], mpos[1])
				print clicked
				if clicked:
					if clicked.onClick:
						for event in clicked.onClick:
							event(clicked, gui)
	pygame.display.flip()
pygame.quit()
